package charactor;

import java.awt.Container;
import java.sql.*;

import javax.swing.*;

public class test {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        }catch(ClassNotFoundException e) {
            e.printStackTrace();
        }
        String ipurl="jdbc:mysql://localhost:3306/kcb?useSSL=false&serverTimezone=UTC";
        String userName="root";
        String password="root";
        try {
            Connection c=DriverManager.getConnection(ipurl,userName,password);
            //TYPE_SCROLL_SENSITIVE 该常量指示可滚动并且通常受 ResultSet 底层数据更改影响的ResultSet 对象的类型。
            //CONCUR_READ_ONLY 缺省类型。该常量指示不可以更新的 ResultSet 对象的并发模式。
            Statement s=c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            String sql ="select *from kcb_info";
            ResultSet rs=s.executeQuery(sql);
            rs.last();
            int row=rs.getRow();
            String[][] bt1=new String[row][8];
            int i=0;
            rs.beforeFirst();
            while(rs.next()) {
                for(int j=0;j<8;j++) {
                    bt1[i][j]=rs.getString(j+1);
                }
                i++;
            }
            JFrame jf=new JFrame("课程表");
            Container co=jf.getContentPane();
            String[] bt= {"序号","星期一","星期二","星期三","星期四","星期五","星期六","星期日"};

            JTable jt=new JTable(bt1,bt);
            JScrollPane jsp=new JScrollPane(jt);
            co.add(jsp);

            jf.setSize(400,200);
            jf.setVisible(true);
            jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        }catch(SQLException e) {
            e.printStackTrace();
        }
    }
}
